﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Waker.APIs.ZKT;
using Waker.Common;

namespace Waker.Cards
{
    public partial class FormLeaveStaff : Waker.Base.FormBaseToolBar
    {
        public FormLeaveStaff()
        {
            InitializeComponent();  
            this.Load += new EventHandler(FormStaff_Load); 
        }



        void FormStaff_Load(object sender, EventArgs e)
        {
            FormRefresh();
        }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            FormRefresh();
        }
        public override void FormRefresh()
        {
            //bool? isChek = null;
            //if (chkGrantCard.CheckState != CheckState.Indeterminate)
            //    isChek = chkGrantCard.Checked;
            var dt = new BAL.BAL_Cards().EmployeeSeach(txtEmp_Name.Text.Trim(), txtEmp_No.Text.Trim(), txtEmp_IDCard.Text.Trim(), null, true);
            this.gridControl1.DataSource = dt;
            if (gridView1.GroupCount > 0)
                gridView1.ExpandGroupRow(gridView1.FocusedRowHandle, false);
        }
        protected override void FormDelete()
        {
            if (gridView1.FocusedRowHandle < 0)
                return;
            var dr = gridView1.GetFocusedDataRow();
            if (dr == null || dr["Emp_ID"] == DBNull.Value)
                return;
            if (UI.ShowWarningOKCancel(string.Format("确定删除员工[{0}]吗?", dr["Emp_Name"]), "删除提示") != DialogResult.OK)
                return;
            var res = new BAL.BAL_Cards().DeleteEmployee(dr["Emp_ID"].ToString());
            if (res)
            {
                UI.ShowInfo("删除成功");
                FormRefresh();
            }
            else
            {
                UI.ShowError("删除失败");
            }
        }
        void barbtnResume_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (gridView1.FocusedRowHandle < 0)
                return;
            var dr = gridView1.GetFocusedDataRow();
            if (dr == null)
                return;
            if (!UI.ShowOKCancelReturnBool(string.Format("确定要将[{0}]复职?", dr["Emp_Name"])))
            {
                return;
            }
            var isok = new BAL.BAL_Cards().SetEmployeeLeave(dr["Emp_ID"].ToString(), false);
            if (isok)
            {
                UI.ShowInfo("复职成功");
                FormRefresh();
            }
            else
                UI.ShowError("复职设置失败");
        }
    }
}
